Imports PTT.CarRes.Data

Public Class ClassQueryInvWareaGroup
    Public Function Add(ByVal InvWareaGroup As QueryInvWareaGroup, ByVal StrConn As String) As Boolean
        Dim ClsInvWareaGroup As New ClassInvWareaGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvWareaGroup.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvWareaGroup
            .WareaGroupId = InvWareaGroup.WareaGroupId
            .WareaGroupName = InvWareaGroup.WareaGroupName
            .WareaGroupDesc = InvWareaGroup.WareaGroupDesc
            ret = .USP_Save(Conn)
        End With
        ClsInvWareaGroup.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvWareaGroup As QueryInvWareaGroup, ByVal Strconn As String) As Boolean
        Dim ClsInvWareaGroup As New ClassInvWareaGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvWareaGroup.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvWareaGroup
            .WareaGroupId = InvWareaGroup.WareaGroupId
            .Load(Conn)
            .WareaGroupName = InvWareaGroup.WareaGroupName
            .WareaGroupDesc = InvWareaGroup.WareaGroupDesc
            ret = .USP_Update(Conn)
        End With
        ClsInvWareaGroup.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvWareaGroup As QueryInvWareaGroup, ByVal Strconn As String) As Boolean
        Dim ClsInvWareaGroup As New ClassInvWareaGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvWareaGroup.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvWareaGroup
            .WareaGroupId = InvWareaGroup.WareaGroupId
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvWareaGroup.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaWareaGroupId As String = "", _
    Optional ByVal ParaWareaGroupName As String = "", _
    Optional ByVal ParaWareaGroupDesc As String = "", Optional ByVal Strconn As String = "") As QueryInvWareaGroups
        Dim ClsInvWareaGroup As New ClassInvWareaGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvWareaGroup.ConnectionOpen(Strconn)
        Dim ret As QueryInvWareaGroups = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvWareaGroup"
        If ParaWareaGroupId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(WareaGroupId = " & ParaWareaGroupId & ")"
        End If
        If ParaWareaGroupName & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(WareaGroupName like '%" & ParaWareaGroupName & "%')"
        End If
        If ParaWareaGroupDesc & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(WareaGroupDesc like '%" & ParaWareaGroupDesc & "%')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvWareaGroup
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvWareaGroups

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvWareaGroup( _
                              .Item("WareaGroupId") & "", _
                              .Item("WareaGroupName") & "", _
                              .Item("WareaGroupDesc") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvWareaGroup.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaWareaGroupId As String = "", Optional ByVal Strconn As String = "") As QueryInvWareaGroups
        Dim ClsInvWareaGroup As New ClassInvWareaGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvWareaGroup.ConnectionOpen(Strconn)
        Dim ret As QueryInvWareaGroups = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvWareaGroup"
        If ParaWareaGroupId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(WareaGroupId = " & ParaWareaGroupId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvWareaGroup
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvWareaGroups

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvWareaGroup( _
                              .Item("WareaGroupId") & "", _
                              .Item("WareaGroupName") & "", _
                              .Item("WareaGroupDesc") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvWareaGroup.ConnectionClose(Conn)
        Return ret
    End Function
End Class